package com.yootk.config;

import com.yootk.event.YootkEvent;
import com.yootk.vo.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

/**
 * 事件监听配置类
 */
@Slf4j
@Configuration
public class EventListenerConfig {

    //@EventListener
    public void handleAllEvent(Object event) {      // 监听所有事件
        log.info("【handleAllEvent】{}", event);
    }

    @EventListener
    public void handleYootkEvent(YootkEvent event) {    // 监听指定事件
        log.info("【handleYootkEvent】{}", event);
    }

    @EventListener(condition = "#event.message.title == 'yootk'")
    public void handleConditionEvent(YootkEvent event) {    // 条件监听
        log.info("【handleConditionEvent】{}", event);
    }

    @EventListener
    public void handleObjectEvent(Message message) {    // 监听Message类型
        log.info("【handleObjectEvent】{}", message);
    }
}
